var express = require("express");
var router = express.Router();
const Result = require("../utils/result");
const commentService = require("../services/commentService");

router.post("/add", async function (req, res) {
  const commentData = req.body;
  await commentService.add(commentData);
  res.json(Result.success());
});

router.get("/delete", async function (req, res) {
  const { commentId, parentCommentId, postId, userId } = req.query;
  await commentService.delete(commentId, parentCommentId, postId, userId);
  res.json(Result.success());
});

router.get("/getList", async function (req, res) {
  const { postId, page, size } = req.query;
  const { rows, count } = await commentService.getList(postId, size, page);
  res.json(
    Result.success({
      count,
      comments: rows,
    })
  );
});

module.exports = router;
